package com.asset.dispoal.file.bank.domain.service.command;

import com.asset.dispoal.commom.page.PagingQuery;
import com.asset.dispoal.file.bank.domain.db.mapper.FileBankMapper;
import com.asset.dispoal.file.bank.dto.FileBankDetailPageRequest;
import com.asset.dispoal.file.bank.dto.FileBankDetailResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.protocol.Result;
import tech.mhuang.pacebox.springboot.protocol.data.Page;
import tech.mhuang.pacebox.springboot.protocol.data.PageVO;

@Component
public class FileBankDetailPageCommand implements BaseCommand<FileBankDetailPageRequest, Result> {

    @Autowired
    private FileBankMapper fileBankMapper;

    @Override
    public Result execute(FileBankDetailPageRequest request) {
        int count = fileBankMapper.pageDetailCount(request);
        Page<FileBankDetailPageRequest> pageRequest = PagingQuery.getPage(count, request);
        PageVO<FileBankDetailResponse> pageVO = new PageVO<>();
        pageVO.setTotalSize(count);
        if (pageRequest != null) {
            pageVO.setResult(fileBankMapper.pageDetail(pageRequest));
        }
        return Result.ok(pageVO);
    }
}